package org.jeecgframework.web.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.hibernate.criterion.Restrictions;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.MyBeanUtils;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.oConvertUtils;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.jeecgframework.web.service.CbsInvoiceInfoServiceI;
import org.jeecgframework.web.system.pojo.base.CbsInvoiceInfoEntity;
import org.jeecgframework.web.system.pojo.base.TSDepart;
import org.jeecgframework.web.system.pojo.base.ZyCinemaEntity;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.util.FileBean;
import org.jeecgframework.web.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;



/**
 * @Title: Controller
 * @Description: cbs_invoice_info
 * @author onlineGenerator
 * @date 2016-08-19 10:22:32
 * @version V1.0
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/cbsInvoiceInfoController")
public class CbsInvoiceInfoController extends BaseController {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(CbsInvoiceInfoController.class);

    @Autowired
    private CbsInvoiceInfoServiceI cbsInvoiceInfoService;
    @Autowired
    private SystemService systemService;
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    /**
     * cbs_invoice_info列表 页面跳转
     *
     * @return
     */
    @RequestMapping(params = "cbsInvoiceInfo")
    public ModelAndView cbsInvoiceInfo(HttpServletRequest request) {
        return new ModelAndView("com/zybk/invoice_info/cbsInvoiceInfoList");
    }

    @RequestMapping(params = "datagridSelect")
    public void datagridSelect(CbsInvoiceInfoEntity cbsInvoiceInfo,String belongId,String clientType,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid){

        String hql = "from CbsInvoiceInfoEntity where isActive=1 ";
        if(!"all".equals(cbsInvoiceInfo.getInvoiceGenre())){
            hql += " and invoiceGenre='"+cbsInvoiceInfo.getInvoiceGenre()+"'";
        }
        if(StringUtil.isNotEmpty(belongId)){
            if("0".equals(clientType)){
                hql += " and belongCinema.id='"+belongId+"'";
            }else if("1".equals(clientType)){
                hql += " and belongOrg.id='"+belongId+"'";
            }
        }

        dataGrid.setResults(systemService.findHql(hql));
        TagUtil.datagrid(response, dataGrid);
    }

    public CbsInvoiceInfoEntity setDefault(CbsInvoiceInfoEntity invoice){
        if(invoice != null){
            if(invoice.getBelongCinema() != null){
                cbsInvoiceInfoService.executeSql("update cbs_invoice_info set is_default=0 where belong_cinema='"+invoice.getBelongCinema().getId()+"'");
            }
            if(invoice.getBelongOrg() != null){
                cbsInvoiceInfoService.executeSql("update cbs_invoice_info set is_default=0 where belong_org='"+invoice.getBelongOrg().getId()+"'");
            }
            invoice.setIsDefault((Integer)1);
        }
        return invoice;
    }

    @RequestMapping(params = "setAsDefault")
    @ResponseBody
    public AjaxJson setAsDefault(CbsInvoiceInfoEntity invoice){
        AjaxJson re = new AjaxJson();
        String invoiceId = invoice.getId();
        re.setSuccess(true);
        if(oConvertUtils.isEmpty(invoiceId)){
            re.setSuccess(false);
        }else{
            CbsInvoiceInfoEntity invoiceStored = cbsInvoiceInfoService.get(CbsInvoiceInfoEntity.class,invoiceId);
            invoice.setId(null);
            try {
                MyBeanUtils.copyBeanNotNull2Bean(invoice,invoiceStored);
            } catch (Exception e) {
                e.printStackTrace();
            }
            setDefault(invoiceStored);
            cbsInvoiceInfoService.saveOrUpdate(invoiceStored);
        }
        return re;
    }

    @RequestMapping(params = "goInvoiceSelect")
    public ModelAndView goInvoiceSelect(String cinemaId,String procurement,int clientType,ModelMap modelMap){
        modelMap.put("invoiceGenre","all");
        modelMap.put("clientType",clientType);
        modelMap.put("belongId",oConvertUtils.getString(cinemaId));
        if(clientType == 1){
            modelMap.put("belongId",oConvertUtils.getString(procurement));
        }
        return new ModelAndView("com/zybk/invoice_info/cbsInvoiceInfoListSelect");
    }

    /**
     * easyui AJAX请求数据
     *
     * @param request
     * @param response
     * @param dataGrid
     * @param cbsInvoiceInfo
     */

    @RequestMapping(params = "datagrid")
    public void datagrid(CbsInvoiceInfoEntity cbsInvoiceInfo,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery(CbsInvoiceInfoEntity.class, dataGrid);
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cbsInvoiceInfo, request.getParameterMap());
        try{
            //自定义追加查询条件
           /* String query_clientName_begin = request.getParameter("clientName_begin");
            String query_clientName_end = request.getParameter("clientName_end");
            if(StringUtil.isNotEmpty(query_clientName_begin)){
                cq.ge("clientName", Integer.parseInt(query_clientName_begin));
            }
            if(StringUtil.isNotEmpty(query_clientName_end)){
                cq.le("clientName", Integer.parseInt(query_clientName_end));
            }
            String query_clientTaxnum_begin = request.getParameter("clientTaxnum_begin");
            String query_clientTaxnum_end = request.getParameter("clientTaxnum_end");
            if(StringUtil.isNotEmpty(query_clientTaxnum_begin)){
                cq.ge("clientTaxnum", Integer.parseInt(query_clientTaxnum_begin));
            }
            if(StringUtil.isNotEmpty(query_clientTaxnum_end)){
                cq.le("clientTaxnum", Integer.parseInt(query_clientTaxnum_end));
            }
            String query_clientPhone_begin = request.getParameter("clientPhone_begin");
            String query_clientPhone_end = request.getParameter("clientPhone_end");
            if(StringUtil.isNotEmpty(query_clientPhone_begin)){
                cq.ge("clientPhone", Integer.parseInt(query_clientPhone_begin));
            }
            if(StringUtil.isNotEmpty(query_clientPhone_end)){
                cq.le("clientPhone", Integer.parseInt(query_clientPhone_end));
            }*/
        	cq.add(Restrictions.eq("isActive", 1));
            cq.addOrder("createDate", SortDirection.desc);
        }catch (Exception e) {
            throw new BusinessException(e.getMessage());
        }
        cq.add();
        this.cbsInvoiceInfoService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }

    /**
     * cbs_invoice_info新增页面跳转
     *
     * @return
     */
    @RequestMapping(params = "goAdd")
    public ModelAndView goAdd(CbsInvoiceInfoEntity cbsInvoiceInfo, HttpServletRequest req) {
        if (StringUtil.isNotEmpty(cbsInvoiceInfo.getId())) {
            cbsInvoiceInfo = cbsInvoiceInfoService.getEntity(CbsInvoiceInfoEntity.class, cbsInvoiceInfo.getId());
            req.setAttribute("cbsInvoiceInfoPage", cbsInvoiceInfo);
        }
        return new ModelAndView("com/zybk/invoice_info/cbsInvoiceInfo-add");
    }

    /**
     * @author lishuai
     * 2016年8月19日 上午11:19:46
     * Description 弹出式机构选择页
     * @param request
     * @return
     */
    @RequestMapping(params = "zyOrgs")
    public ModelAndView zyOrgs(HttpServletRequest request) {
        return new ModelAndView("com/zybk/invoice_info/zyChooseOrgs");
    }

    /**
     * @author lishuai
     * 2016年8月19日 上午11:18:33
     * Description  弹出式机构选择页
     * @param tsDepart
     * @param request
     * @param response
     * @param dataGrid
     */
    @RequestMapping(params = "chooseDepartListDatagrid")
    public void chooseDepartListDatagrid(TSDepart tsDepart,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery(TSDepart.class, dataGrid);
        cq.add(Restrictions.or(Restrictions.eq("logicDelete", "0"),Restrictions.isNull("logicDelete")));//基本过滤条件，只查询未删除的数据
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tsDepart, request.getParameterMap());
        cq.add();
        this.systemService.getDataGridReturn(cq, true);
        TagUtil.datagrid(response, dataGrid);
    }

    @RequestMapping(params = "goWxAdd")
    public ModelAndView goWxAdd(String id,String cinemaid){
        ModelAndView mv = new ModelAndView("com/wx/added_product/procurement/invoice-add");
        if(StringUtil.isNotEmpty(id)){
            mv.addObject("ad",cbsInvoiceInfoService.get(CbsInvoiceInfoEntity.class,id));
            mv.addObject("edit",1);
        }
        if(StringUtil.isNotEmpty(cinemaid)){
            mv.addObject("cm",cinemaid);
        }
        return mv;
    }




    /**
     * 添加客户开票信息
     *
     * @param cbsInvoiceInfo
     * @return
     */
    @RequestMapping(params = "doAdd")
    @ResponseBody
    public AjaxJson doAdd(CbsInvoiceInfoEntity cbsInvoiceInfo, HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
//        if(StringUtil.isEmpty(cbsInvoiceInfo.getInvoiceGenre())){
//            j.setSuccess(false);
//            j.setMsg("请选择发票类型");
//            return j;
//        }
        if(cbsInvoiceInfo.getIsDefault() == null){
            cbsInvoiceInfo.setIsDefault(0);
        }
        cbsInvoiceInfo.setIsActive((Integer)1);
//        cbsInvoiceInfo.setIsDefault((Integer)0);
        if(StringUtil.isNotEmpty(cbsInvoiceInfo.getId())){
            return doUpdate(cbsInvoiceInfo,request);
        }
        message = "客户开票信息管理添加成功";
        try{
//			if("dedicated".equals(cbsInvoiceInfo.getInvoiceGenre())){
//				cbsInvoiceInfo.setInvoiceGenre("专用");
//			}else{
//				cbsInvoiceInfo.setInvoiceGenre("普通");
//			}
            if(!cbsInvoiceInfoService.checkCanDoAdd(cbsInvoiceInfo)){
                j.setSuccess(false);
                j.setMsg("发票信息已存在，请勿重复提交!");
                return j;
            }
            cbsInvoiceInfoService.save(cbsInvoiceInfo);
            j.setObj(cbsInvoiceInfo);
            systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
        }catch(Exception e){
            e.printStackTrace();
            message = "客户开票信息管理添加失败";
            throw new BusinessException(e.getMessage());
        }
        j.setMsg(message);
        return j;
    }

    @RequestMapping(params = "getInvoiceById")
    @ResponseBody
    public CbsInvoiceInfoEntity getInvoiceById(String id){
        CbsInvoiceInfoEntity cbsInvoiceInfo = cbsInvoiceInfoService.getEntity(CbsInvoiceInfoEntity.class,oConvertUtils.getString(id));
        return cbsInvoiceInfo;
    }

    @RequestMapping(params = "getDefaultInvoice")
    @ResponseBody
    public List<CbsInvoiceInfoEntity> getDefaultInvoice(String id,int clientType,ModelMap modelMap){
        List<CbsInvoiceInfoEntity> results = new ArrayList<CbsInvoiceInfoEntity>();
        if(clientType == 1){
            results = cbsInvoiceInfoService.findHql("from CbsInvoiceInfoEntity where isDefault=1 and belongOrg.id=?",id);
        }else{
            results = cbsInvoiceInfoService.findHql("from CbsInvoiceInfoEntity where isDefault=1 and belongCinema.id=?",id);
        }
        return results;
    }
    /**
     * @author lishuai
     * 2016年8月28日 下午4:02:57
     * Description 客户税号唯一性验证
     * @param request
     * @param param
     * @return
     */
    @RequestMapping(params="getInvoiceInfobyclientTaxnum")
    @ResponseBody
    public Map<String, Object> getInvoiceInfobyclientTaxnum(HttpServletRequest request,String param){
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer sb= new StringBuffer("from CbsInvoiceInfoEntity where clientTaxnum = ?");
        if(StringUtil.isNotEmpty(param)){
            List<CbsInvoiceInfoEntity> info=systemService.findHql(sb.toString(), param);
            if(info.size()>0){
                map.put("info", "税号已存在");
                map.put("status","n" );
            }else{
                map.put("info", "验证通过");
                map.put("status", "y");
            }
        }

        return map;
    }

    /**
     * @author lishuai
     * 2016年8月28日 下午4:07:43
     * Description 客户电话唯一性验证
     * @param request
     * @param param
     * @return
     */
    @RequestMapping(params="getInvoiceInfobyclientPhone")
    @ResponseBody
    public Map<String, Object> getInvoiceInfobyclientPhone(HttpServletRequest request,String param){
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer sb= new StringBuffer("from CbsInvoiceInfoEntity where clientPhone = ?");
        if(StringUtil.isNotEmpty(param)){
            List<CbsInvoiceInfoEntity> info=systemService.findHql(sb.toString(), param);
            if(info.size()>0){
                map.put("info", "电话号已存在");
                map.put("status","n" );
            }else{
                map.put("info", "验证通过");
                map.put("status", "y");
            }
        }

        return map;
    }

    /**
     * @author lishuai
     * 2016年8月28日 下午4:10:35
     * Description 客户银行账号唯一性验证
     * @param request
     * @param param
     * @return
     */
    @RequestMapping(params="getInvoiceInfobyclientBankaccount")
    @ResponseBody
    public Map<String, Object> getInvoiceInfobyclientBankaccount(HttpServletRequest request,String param){
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuffer sb= new StringBuffer("from CbsInvoiceInfoEntity where clientBankaccount = ?");
        if(StringUtil.isNotEmpty(param)){
            List<CbsInvoiceInfoEntity> info=systemService.findHql(sb.toString(), param);
            if(info.size()>0){
                map.put("info", "该银行账号已存在");
                map.put("status","n" );
            }else{
                map.put("info", "验证通过");
                map.put("status", "y");
            }
        }

        return map;
    }
    /**
     * cbs_invoice_info编辑页面跳转
     *
     * @return
     */
    @RequestMapping(params = "goUpdate")
    public ModelAndView goUpdate(CbsInvoiceInfoEntity cbsInvoiceInfo, HttpServletRequest req) {
        if (StringUtil.isNotEmpty(cbsInvoiceInfo.getId())) {
            cbsInvoiceInfo = cbsInvoiceInfoService.getEntity(CbsInvoiceInfoEntity.class, cbsInvoiceInfo.getId());
            req.setAttribute("cbsInvoiceInfoPage", cbsInvoiceInfo);
        }
        if(oConvertUtils.getString(req.getParameter("load")).equals("detail")){
            return new ModelAndView("com/zybk/invoice_info/cbsInvoiceInfo-update");
        }
        return new ModelAndView("com/zybk/invoice_info/cbsInvoiceInfo-add");
    }

    /**
     * 更新cbs_invoice_info
     *
     * @param cbsInvoiceInfo
     * @return
     */
    @RequestMapping(params = "doUpdate")
    @ResponseBody
    public AjaxJson doUpdate(CbsInvoiceInfoEntity cbsInvoiceInfo, HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        message = "客户开票信息管理更新成功";
        if(cbsInvoiceInfo.getBelongCinema() != null && StringUtil.isEmpty(cbsInvoiceInfo.getBelongCinema().getId())){
            cbsInvoiceInfo.setBelongCinema(null);
        }
        if(cbsInvoiceInfo.getBelongOrg() != null && StringUtil.isEmpty(cbsInvoiceInfo.getBelongOrg().getId())){
            cbsInvoiceInfo.setBelongOrg(null);
        }
        CbsInvoiceInfoEntity t = cbsInvoiceInfoService.get(CbsInvoiceInfoEntity.class, cbsInvoiceInfo.getId());
        try {
            MyBeanUtils.copyBeanNotNull2Bean(cbsInvoiceInfo, t);
            setDefault(cbsInvoiceInfo);
            cbsInvoiceInfoService.saveOrUpdate(t);
            j.setObj(t);
            systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
        } catch (Exception e) {
            e.printStackTrace();
            message = "客户开票信息管理更新失败";
            throw new BusinessException(e.getMessage());
        }
        j.setMsg(message);
        return j;
    }



    /**
     * 删除cbs_invoice_info
     *
     * @return
     */
    @RequestMapping(params = "doDel")
    @ResponseBody
    public AjaxJson doDel(CbsInvoiceInfoEntity cbsInvoiceInfo, HttpServletRequest request) {
        AjaxJson j = new AjaxJson();
        cbsInvoiceInfo = systemService.getEntity(CbsInvoiceInfoEntity.class, cbsInvoiceInfo.getId());
        message = "客户开票信息管理删除成功";
        try{
            cbsInvoiceInfo.setIsDefault((Integer)0);
            cbsInvoiceInfo.setIsActive((Integer)0);
            systemService.saveOrUpdate(cbsInvoiceInfo);
            systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
        }catch(Exception e){
            e.printStackTrace();
            message = "客户开票信息管理删除失败";
            throw new BusinessException(e.getMessage());
        }
        j.setMsg(message);
        return j;
    }

    /**
     * 批量删除cbs_invoice_info
     *
     * @return
     */
    @RequestMapping(params = "doBatchDel")
    @ResponseBody
    public AjaxJson doBatchDel(String ids,HttpServletRequest request){
        AjaxJson j = new AjaxJson();
        message = "客户开票信息管理删除成功";
        try{
            for(String id:ids.split(",")){
                CbsInvoiceInfoEntity cbsInvoiceInfo = systemService.getEntity(CbsInvoiceInfoEntity.class,
                        id
                );
                cbsInvoiceInfo.setIsDefault((Integer)0);
                cbsInvoiceInfo.setIsActive((Integer)0);
                systemService.saveOrUpdate(cbsInvoiceInfo);
//                cbsInvoiceInfoService.delete(cbsInvoiceInfo);
                systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
            }
        }catch(Exception e){
            e.printStackTrace();
            message = "客户开票信息管理删除失败";
            throw new BusinessException(e.getMessage());
        }
        j.setMsg(message);
        return j;
    }

    /**
     * 导入功能跳转
     *
     * @return
     */
    @RequestMapping(params = "upload")
    public ModelAndView upload(HttpServletRequest req) {
        req.setAttribute("sessionId", req.getSession().getId());
        return new ModelAndView("com/zybk/invoice_info/cbsInvoiceInfoupload");
    }

    /**
     * 导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping(params = "exportXls")
    public String exportXls(CbsInvoiceInfoEntity cbsInvoiceInfo,HttpServletRequest request,HttpServletResponse response
            , DataGrid dataGrid,ModelMap modelMap) {
        CriteriaQuery cq = new CriteriaQuery(CbsInvoiceInfoEntity.class, dataGrid);
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, cbsInvoiceInfo, request.getParameterMap());
        List<CbsInvoiceInfoEntity> cbsInvoiceInfos = this.cbsInvoiceInfoService.getListByCriteriaQuery(cq,false);
        modelMap.put(NormalExcelConstants.FILE_NAME,"cbs_invoice_info");
        modelMap.put(NormalExcelConstants.CLASS,CbsInvoiceInfoEntity.class);
        modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("cbs_invoice_info列表", "导出人:"+ResourceUtil.getSessionUserName().getRealName(),
                "导出信息"));
        modelMap.put(NormalExcelConstants.DATA_LIST,cbsInvoiceInfos);
        return NormalExcelConstants.JEECG_EXCEL_VIEW;
    }
    /**
     * 导出excel 使模板
     *
     * @param request
     * @param response
     */
    @RequestMapping(params = "exportXlsByT")
    public String exportXlsByT(CbsInvoiceInfoEntity cbsInvoiceInfo,HttpServletRequest request,HttpServletResponse response
            , DataGrid dataGrid,ModelMap modelMap) {
        modelMap.put(TemplateExcelConstants.FILE_NAME, "cbs_invoice_info");
        modelMap.put(TemplateExcelConstants.PARAMS,new TemplateExportParams("Excel模板地址"));
        modelMap.put(TemplateExcelConstants.MAP_DATA,null);
        modelMap.put(TemplateExcelConstants.CLASS,CbsInvoiceInfoEntity.class);
        modelMap.put(TemplateExcelConstants.LIST_DATA,null);
        return TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW;
    }

    @SuppressWarnings("unchecked")
    @RequestMapping(params = "importExcel")
    @ResponseBody
    public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
        AjaxJson j = new AjaxJson();
        try {
            j.setMsg("客户开票信息导入成功");
            message="";
            FileBean filebean=FileUtil.uploadFile(request);
            List<Map<String, Object>> dataList= org.jeecgframework.web.util.ExcelImportUtil.importExcel(filebean, 0);
				/*ZyCinemaEntity  belongCinema=systemService.findUniqueByProperty(ZyCinemaEntity.class, "name", dataList.get(1).get("8") );
				TSDepart  depart=systemService.findUniqueByProperty(TSDepart.class,"shortname",dataList.get(1).get("8"));
				if(oConvertUtils.isEmpty(depart)){
					System.out.println("depart色即是空");
				}else{
					System.out.println("depart不为空");
				}
				if(oConvertUtils.isEmpty(belongCinema)){
					System.out.println("belongCinema色即是空");
				}else{
					System.out.println("belongCinema不为空");
				}*/
            List<CbsInvoiceInfoEntity> cbsInvoicelist=new ArrayList<CbsInvoiceInfoEntity>();
            for (int i = 1; i <dataList.size(); i++) {
                CbsInvoiceInfoEntity cbsInvoiceInfo=new CbsInvoiceInfoEntity();
                String fapiao=!StringUtil.isNotEmpty(dataList.get(i).get("0")) ? "":dataList.get(i).get("0").toString();
                String kehuname=!StringUtil.isNotEmpty(dataList.get(i).get("1")) ? "":dataList.get(i).get("1").toString();
                String shuihao=!StringUtil.isNotEmpty(dataList.get(i).get("2")) ? "":dataList.get(i).get("2").toString();
                String address=!StringUtil.isNotEmpty(dataList.get(i).get("3")) ? "":dataList.get(i).get("3").toString();
                String phone=!StringUtil.isNotEmpty(dataList.get(i).get("4")) ? "":dataList.get(i).get("4").toString();
                String yhname=!StringUtil.isNotEmpty(dataList.get(i).get("5")) ? "":dataList.get(i).get("5").toString();
                String yhzh=!StringUtil.isNotEmpty(dataList.get(i).get("6")) ? "":dataList.get(i).get("6").toString();
				   /* String type=!StringUtil.isNotEmpty(dataList.get(i).get("7")) ? "":dataList.get(i).get("7").toString();*/
                // String typename=!StringUtil.isNotEmpty(dataList.get(i).get("8")) ? "":dataList.get(i).get("8").toString();
                ZyCinemaEntity  belongCinema=systemService.findUniqueByProperty(ZyCinemaEntity.class, "name", dataList.get(i).get("8") );
                TSDepart  depart=systemService.findUniqueByProperty(TSDepart.class,"shortname",dataList.get(i).get("8"));
                if(!oConvertUtils.isEmpty(belongCinema)){
                    cbsInvoiceInfo.setGenre("影院");
                    cbsInvoiceInfo.setBelongCinema(belongCinema);
                }else{
                    cbsInvoiceInfo.setGenre("机构");
                    cbsInvoiceInfo.setBelongOrg(depart);
                }
                cbsInvoiceInfo.setInvoiceGenre(fapiao);
                cbsInvoiceInfo.setClientName(kehuname);
                cbsInvoiceInfo.setClientTaxnum(shuihao);
                cbsInvoiceInfo.setClientAddress(address);
                cbsInvoiceInfo.setClientPhone(phone);
                cbsInvoiceInfo.setClientBankname(yhname);
                cbsInvoiceInfo.setClientBankaccount(yhzh);
                // System.out.println("影院联系人："+belongCinema.getEname()+"\t"+StringUtil.isEmpty(belongCinema.getEname()));
                //System.out.println("机构联系人"+depart.getShortname());
				   /* if (!StringUtil.isEmpty(belongCinema.getEname())){
				    	cbsInvoiceInfo.setGenre("影院");
				    	cbsInvoiceInfo.setBelongCinema(belongCinema);
					}else{
						cbsInvoiceInfo.setGenre("机构");
						cbsInvoiceInfo.setBelongOrg(depart);
					}*/
                cbsInvoicelist.add(cbsInvoiceInfo);
            }
            cbsInvoiceInfoService.batchSave(cbsInvoicelist);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return j;
    }
}
